<!DOCTYPE html>
<html>

<head lang="en">
    <title>我的评论</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>

        $(function () {

            //当前页的input框
            var currentInput = $("#currentPage");

            //用于存储游记的数组容器
            var arr = [];

            //总页数
            var pages = 1;


            var params = getParams();
            /**
             * 查询该用户评论的攻略
             */
            function query(href,fun) {
                //获取当前页的值
                var currentPage = currentInput.val();//1
                $.get(href, {currentPage: currentPage, userId: params.userId}, function (data) {
                    console.log(data);
                    //合并两个数组到第一个参数数组上
                    $.merge(arr, data.list);
                    //用于渲染时循环,循环时是取list的属性出来
                    var json = {
                        list: arr
                    };
                    //渲染数据
                    fun(json);
                    //设置总页数
                    pages = data.pages;
                })
                //当前页input框+1
                currentInput.val(parseInt(currentPage) + 1);
            }
            var strategyHref = '/strategyComments/{userId}';
            var dailyNewsHref='/dailyNewsComment/{userId}';
            function strategy(data){
                $("#pills-strategy").renderValues(data,{
                    getHref:getHref
                });
            }
            function dailyNews(data){
                //console.log(data);
                $("#pills-dailyNews").renderValues(data, {
                    getHref: getHref
                });
            }
            var judge = 1;
            query(strategyHref,strategy);


            $('#pills-top-dailyNews').click(function () {
                currentInput.val(1);
                arr = [];
                query(dailyNewsHref,dailyNews);
                judge = 2;
            })


            //当页面滚动条变化时，执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    var currentPage = currentInput.val();
                    //判断是否小于或等于最后一页,如果是就去查询
                    if(currentPage<=pages) {
                        if (judge == 1) {
                            query(strategyHref,strategy);
                        }else if(judge ==2) {
                            query(dailyNewsHref,dailyNews);
                        }
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底了!',
                            autoClose: 1000
                        });

                    }
                }
            });

        })
    </script>
</head>

<body>
<!--从第二页开始-->
<input type="hidden" name="currentPage" id="currentPage" value="1">

<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的评论</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-collect"
    role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" id="pills-top-strategy" data-toggle="pill" href="#pills-strategy">
            <span style="font-weight: bold;">攻略评论</span>
        </a>
    </li>
    <li class="nav-item" >
        <a class="nav-link" id="pills-top-dailyNews" data-toggle="pill" href="#pills-dailyNews">
            <span style="font-weight: bold;">日报评论</span>
        </a>
    </li>
</ul>
<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-strategy">
        <div class="container commend" render-loop="list">
            <!---->
            <a data-href="../strategyCatalogs.html?strategyId=" render-key="list.strategy.id" render-fun="getHref">
                <b style="color: #9E9E9E" render-html="list.user.nickName"></b>&nbsp;&nbsp;&nbsp;<b
                    style="color: green">评论了</b>&nbsp;&nbsp;&nbsp;<b style="color:  #9E9E9E"
                                                                     render-html="list.strategy.title"></b>
                <img render-src="list.strategy.coverUrl">
                <b>评论时间: <span render-html="list.createTime"></span><br><br>
                </b>
            </a>
        </div>
    </div>

    <div class="tab-pane fade" id="pills-dailyNews">
        <!-- <div class="container dailyNews">
             <dl class="list" render-loop="list">
                 <dd>
                     &lt;!&ndash;render-key="list.dailyNews.id" render-fun="getHref"&ndash;&gt;
                     <a data-href="/newsContent.html?news_id=">
                         <img render-src="list.dailyNews.coverImgUrl" width="300px">
                         <b style="color: #9E9E9E" render-html="list.user.nickName"></b>&nbsp;&nbsp;&nbsp;<b
                             style="color: green">评论了</b>&nbsp;&nbsp;&nbsp;<b style="color:  #9E9E9E"
                                                                              render-html="list.news.title"></b>
                         &lt;!&ndash;  <p>收藏时间 <span render-html="list.createTime"></span>
                           </p>&ndash;&gt;
                     </a>
                 </dd>
             </dl>
         </div>-->
        <div class="container commend" render-loop="list">
            <!--render-key="list.strategy.id" render-fun="getHref"-->
            <a data-href="../newsContent.html?news_id=" render-key="list.news.id" render-fun="getHref">
                <b style="color: #9E9E9E" render-html="list.user.nickName"></b>&nbsp;&nbsp;&nbsp;<b
                    style="color: green">评论了</b>&nbsp;&nbsp;&nbsp;<b style="color:  #9E9E9E"
                                                                     render-html="list.news.title"></b><b
                    style="color:  #9E9E9E">日报</b>
                <img render-src="list.news.coverImgUrl">
                <b>评论时间: <span render-html="list.releaseTime"></span>
                </b><br><br>
            </a>
        </div>
    </div>
</div>


</body>

</html>


